package br.ufrgs.meetapp.models;

import br.ufrgs.meetapp.enums.MessageCode;


/***
 * Model for the identification message, thats sent to the the server before start sending the positions. Extends the MFTMessage class. Provides the possibility of serialization according to the MFT protocol 
 * @author Benites
 *
 */
public class IdentificationMessage extends MFTMessage {
	
	// TODO: Verify if this attribute must be static and whether it should stay in this class or in other one
	private final String APPLICATION_NAME = "MFTAndroid";
	
	/***
	 * PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
	 *	String version = packageInfo.versionName;
	 */
	private String applicationVersionName; 
	
	/***
	 * ((CurrentDevice) LoginActivity.loggedUser.getDevice()).getPhoneInfo().getLine1Number();
	 */
	private String deviceLineNumber; 
	
	/***
	 * ((CurrentDevice) LoginActivity.loggedUser.getDevice()).getPhoneInfo().getNetworkOperatorName();
	 */
	private String deviceNetworkOperatorName;
	
	
	/***
	 * ((CurrentDevice) LoginActivity.loggedUser.getDevice()).getPhoneInfo().getDeviceSoftwareVersion();
	 */
	private String deviceSoftwareVersion;
	private String imei;
	private String deviceProvider;
	
	public IdentificationMessage(){
	}
	
	public IdentificationMessage(String _applicationVersionName, String _deviceLineNumber, String _deviceNetworkOperatorName, String _deviceSoftwareVersion, String _deviceProvider, String _imei){
		applicationVersionName = _applicationVersionName;
		deviceLineNumber = _deviceLineNumber;
		deviceNetworkOperatorName = _deviceNetworkOperatorName;
		deviceSoftwareVersion = _deviceSoftwareVersion;
		imei = _imei;
		deviceProvider = _deviceProvider;
	}
	
	/***
	 * Returns the serialized identification message 
	 * @return Byte array to be send to MFT listener
	 */
	@Override
	public byte[] getSerializedMessage() {
		
		String identificationData = imei + "," + deviceLineNumber + "," + deviceProvider + "," + deviceNetworkOperatorName
				+ "," + deviceSoftwareVersion + "," + APPLICATION_NAME + "," + applicationVersionName;
		
		createByteMessage((getStringByteArray(identificationData).length - BYTE_ORDER_MARK_BYTES), MessageCode.IDENTIFICATION.getByteCode());
		writeStringAtMessageIndex(identificationData, MESSAGE_BODY_INDEX);
		finishByteMessage();
		
		return byteMessage;
	}
	
	public String getApplicationVersionName() {
		return applicationVersionName;
	}

	public void setApplicationVersionName(String applicationVersionName) {
		this.applicationVersionName = applicationVersionName;
	}

	public String getDeviceLineNumber() {
		return deviceLineNumber;
	}

	public void setDeviceLineNumber(String deviceLineNumber) {
		this.deviceLineNumber = deviceLineNumber;
	}

	public String getDeviceNetworkOperatorName() {
		return deviceNetworkOperatorName;
	}

	public void setDeviceNetworkOperatorName(String deviceNetworkOperatorName) {
		this.deviceNetworkOperatorName = deviceNetworkOperatorName;
	}

	public String getDeviceSoftwareVersion() {
		return deviceSoftwareVersion;
	}

	public void setDeviceSoftwareVersion(String deviceSoftwareVersion) {
		this.deviceSoftwareVersion = deviceSoftwareVersion;
	}

	public String getImei() {
		return imei;
	}

	public void setImei(String imei) {
		this.imei = imei;
	}

	public String getDeviceProvider() {
		return deviceProvider;
	}

	public void setDeviceProvider(String deviceProvider) {
		this.deviceProvider = deviceProvider;
	}
	
}
